﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace Landscape.Elements
{
    internal class Widget
    {
        public string Name;
        public string Content;
        public Dictionary<string, object> Params = new Dictionary<string, object>();

        public Widget() { 
        
        }

        public Widget(XmlNode node) {
            XmlNode nameAttributeNode = node.Attributes.GetNamedItem("name");

            if (nameAttributeNode == null || nameAttributeNode.Value.Length == 0)
            {
                throw new XmlNodeException("Missing 'name' attribute.", node);
            }

            Name = nameAttributeNode.Value;
            Content = node.InnerXml;

            foreach (XmlNode attr in node.Attributes) {
                // ignore internal parameters and namespaced attributes
                if (attr.Name != "name" && string.IsNullOrEmpty(attr.NamespaceURI)) {
                    Params.Add(attr.Name, attr.Value);
                }
            }
        }
    }
}
